package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.SysFollow;
import com.ruoyi.system.service.ISysFollowService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 关注Controller
 * 
 * @author ruoyi
 * @date 2024-03-01
 */
@RestController
@RequestMapping("/follow")
public class SysFollowController extends BaseController
{
    @Autowired
    private ISysFollowService sysFollowService;

    /**
     * 查询关注列表
     */
    @RequiresPermissions("system:follow:list")
    @GetMapping("/list")
    public TableDataInfo list(SysFollow sysFollow)
    {
        startPage();
        List<SysFollow> list = sysFollowService.selectSysFollowList(sysFollow);
        return getDataTable(list);
    }

    /**
     * 导出关注列表
     */
    @RequiresPermissions("system:follow:export")
    @Log(title = "关注", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysFollow sysFollow)
    {
        List<SysFollow> list = sysFollowService.selectSysFollowList(sysFollow);
        ExcelUtil<SysFollow> util = new ExcelUtil<SysFollow>(SysFollow.class);
        util.exportExcel(response, list, "关注数据");
    }

    /**
     * 获取关注详细信息
     */
    @RequiresPermissions("system:follow:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysFollowService.selectSysFollowById(id));
    }

    /**
     * 新增关注
     */
    @RequiresPermissions("system:follow:add")
    @Log(title = "关注", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysFollow sysFollow)
    {
        return toAjax(sysFollowService.insertSysFollow(sysFollow));
    }

    /**
     * 修改关注
     */
    @RequiresPermissions("system:follow:edit")
    @Log(title = "关注", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysFollow sysFollow)
    {
        return toAjax(sysFollowService.updateSysFollow(sysFollow));
    }

    /**
     * 删除关注
     */
    @RequiresPermissions("system:follow:remove")
    @Log(title = "关注", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysFollowService.deleteSysFollowByIds(ids));
    }
}
